package com.starry.home.viewmodel.main

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.switchMap
import com.starry.core.viewmodel.BaseViewModel
import com.starry.home.logic.model.medical.MedicalBean
import com.starry.home.logic.network.Repository
import com.starry.home.ui.dialog.LoadingAlertDialog

/**
 * Package:com.starry.dotpen_patients.viewmodel.main
 * Author:starr
 * Time:2024/1/28 21:17
 * Description: 展示用户病历本
 */
class MedicalViewModel : BaseViewModel() {

    //获取患者病历
    private val _userBlLiveData = MutableLiveData<Int>()
    val userBl = _userBlLiveData.switchMap {
        userBlId -> Repository.getBlIdByHzId(userBlId)
    }
    fun getUserBl(userBlId: Int) {
        _userBlLiveData.value = userBlId
    }

    //获取病历中医节点
    private val _zyMedicalLiveData = MutableLiveData<Int>()
    val zyMedical = _zyMedicalLiveData.switchMap {
        zyMedicalId -> Repository.getZyJdByBlId(zyMedicalId)
    }
    fun getZyMedical(zyMedicalId: Int) {
        _zyMedicalLiveData.value = zyMedicalId
    }

    //获取病历西医节点
    private val _xyMedicalLiveData = MutableLiveData<Int>()
    val xyMedical = _xyMedicalLiveData.switchMap {
        xyMedicalId -> Repository.getXyJdByBlId(xyMedicalId)
    }
    fun getXyMedical(xyMedicalId: Int) {

        _xyMedicalLiveData.value = xyMedicalId
    }

    //新建病历
    private val _createNewBookLiveData = MutableLiveData<MedicalBean.BlEntity>()
    val createNewBook = _createNewBookLiveData.switchMap {
        createNewBookId -> Repository.saveBook(createNewBookId)
    }
    fun createNewBook(createNewBookId: MedicalBean.BlEntity) {
        _createNewBookLiveData.value = createNewBookId
    }
}